<template>
  <draggable :list="containerMetas" @add="addHandle" class="ivz-dtc-container"
       :group="{pull: false, put: ['list', 'lec'], isDrop: isDrop}">
    <template v-for="item in containerMetas">
      <ivz-basic-list :meta="item" v-if="item.type == 'dl'" />
      <ivz-edit-drawer :meta="item" v-else-if="item.type == 'drawer'" />
      <ivz-edit-modal v-else-if="item.type == 'modal'" :meta="item"/>
    </template>
  </draggable>
</template>

<script>

import {EventBus, MetaEventType} from '@/utils'
import {ComponentType, PathSort} from "@/store/consts";
import MetaUtils from "@/utils/MetaUtils";
import {tableFieldMetas} from "@/metas/DbTableMetas";
import {TableContainerTabMetas} from "@/metas/ContainerMetas";
import IvzBasicList from "@/components/list/IvzBasicList.vue";
import IvzEditModal from "@/components/edit/IvzEditModal.vue";
import IvzEditDrawer from "@/components/edit/IvzEditDrawer.vue";
import {MixinContainer} from "@/components/container/MixinContainer";

export default {
  name: "IvzTableContainer",
  mixins: [MixinContainer],
  components:{IvzEditDrawer, IvzEditModal, IvzBasicList},
  created() {
    this.setContainerTabMetas(TableContainerTabMetas);

    this.switchActiveMetaTo(this.meta)
    this.switchPathTo({name: "表容器"
      , type: ComponentType.Container, sort: PathSort.Container});

    // 监听面包屑切换事件
    EventBus.listener(MetaEventType.path, path => {
      if(path.type == ComponentType.Container) {
        this.switchActiveMetaTo(this.meta)
      }
    });

    // 监听表单元数据初始化事件
    EventBus.listener(MetaEventType.formBeforeCreate, meta => {
      MetaUtils.addToTabMetasBefore(meta['tabMetas'], 'basic', tableFieldMetas);
    })
  },

}
</script>

<style>
.ivz-dtc-container {
  width: 100%;
  height: 100%;
}
</style>
